Skip to content

Fix nil school id bug#701

Draft
zetter-rpf wants to merge 5 commits intomainfrom
fix-nil-school-id-bug
Draft

Fix nil school id bug#701
zetter-rpf wants to merge 5 commits intomainfrom
fix-nil-school-id-bug

Conversation

@zetter-rpf
Copy link
Contributor

Status

  • Closes add issue numbers or delete
  • Related to add issue numbers or delete

Points for consideration:

  • Security
  • Performance

What's changed?

Description of what's been done - bullets are often best

Steps to perform after deploying to production

If the production environment requires any extra work after this PR has been deployed detail it here. This could be running a Rake task, a migration, or upgrading a Gem. That kind of thing.

This might happen when loading a project that no users have started yet. It seems a waste to call the API in this case
I don't like this pattern of rescuing StandardError - it means that errors in development and test are hidden. Also, since we're reporting all the errors to sentry it creates a lot of noise.

In this case, it made an error that happened when listing students on a project that had none. This error happening as soon as a teacher creates a project and even in many tests but because we were rescuing it we didn't notice it. I will fix this problem in the next commit.

More generally, I think we should only handle expected errors - for example, a network error is an expected error. We shouldn't try to deal with unexpected errors as we can't predict what they are or how to handle them.

I've looked at sentry and the only other errors logged by this method in the last month are ones from Faraday - `BadRequestError`, `ForbiddenError`, `ServerError` and `UnauthorizedError`. I'd like to remove this rescue too eventually, but I would want to understand the Faraday errors first.
The .users and .with_users methods are intended to be called on associations, and infer the school by looking for the school in one of the projects in the association.

This can lead to errors (when there are no projects with a school)  or unexpected behaviour if trying to call on a scope containing different projects.

By requiring the school to be passed it, it makes clear to the caller that a school is required and it only works for a single school

As part of this I have fixed the related tests - some of these were passing in unexpected ways because an error was being rescued (see previous commit).
school is a method available as an association so this isn't needed
@cla-bot cla-bot bot added the cla-signed label Feb 27, 2026
When working with this code I found it confusing as specifically returns students, not teachers that may created projects.

I haven't changed the user variable in the projects controller as I think that might be other types of user.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant